package com.hs.chd.dwr;

import java.util.List;
import java.util.Map;

import com.hs.core.db.DBMgr;
import com.hs.core.dwr.DwrHelper;
import com.hs.core.utils.TimeUtil;

public class CatagoryHelper  extends DwrHelper{
	/**
	 * 查询主题分类信息
	 * @param tagid
	 * @return
	 */
	public String queryCatagoryinfo(String tagid){
		StringBuffer buffer = new StringBuffer();
		DBMgr dbo = this.getDbo(this.getHttpServletRequest());
		String sql = "SELECT S.PID, S.TAGNAME, S.TAGNAMENG, S.TAGTYPE, S.ORDERNUM, S.TCMNAMESTR, S.OTHERNAME FROM SCHD_TAGS S where id=?";
		List datalist = dbo.queryList(sql, new Object[]{tagid});
		if(datalist.size() > 0){
			Map data = (Map)datalist.get(0);
			buffer.append(data.get("PID"));
			buffer.append(";");
			buffer.append(data.get("TAGNAME"));
			buffer.append(";");
			buffer.append(data.get("TAGNAMENG"));
			buffer.append(";");
			buffer.append(data.get("TAGTYPE"));
			buffer.append(";");
			buffer.append(data.get("ORDERNUM"));
			buffer.append(";");
			buffer.append(data.get("TCMNAMESTR"));
			buffer.append(";");
			buffer.append(data.get("OTHERNAME"));
			buffer.append(";");
		}
		return buffer.toString();
	}
	/**
	 * 增加主题分类
	 * @param tagname
	 * @param pid
	 * @param userid
	 * @param tagtype
	 * @return
	 */
	public String addCatagory(String tagname,String tagnameng,String pid,String userid,String tagtype,String tcmstr,String othernamestr,String ordernum){
		String seqid = this.getSeqValue("SEQ_SCHD_TAGS_ID");
		
		String sql = "insert into SCHD_TAGS(ID, PID, TAGNAME,TAGNAMENG TAGCODE, IMPDATE, ISDELETE,TAGTYPE, ISROOT,USERID,ORDERNUM,TCMNAMESTR,OTHERNAME) " +
				                     " VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)";
      	int count =	this.getDbo().update(sql, new Object[]{seqid,pid,tagname,tagnameng,tagname,TimeUtil.getCurrentstr1(),1,tagtype,seqid,userid,ordernum,tcmstr,othernamestr});
      	
      	if(count > 0){
      		return seqid+'#' + tagname;
      	}
		return "";
	}
	/**
	 * 修改主题分类
	 * @param tagname
	 * @param pid
	 * @param userid
	 * @param tagtype
	 * @return
	 */
	public String updateCatagory(String tagname,String tagnameng,String tcmstr,String othernamestr,String ordernum,String id){
		//String seqid = this.getSeqValue("SEQ_SCHD_TAGS_ID");
		
		String sql = "update SCHD_TAGS set TAGNAME=?,TAGNAMENG=?,ORDERNUM=?,TCMNAMESTR=?,OTHERNAME=?  where id=? " ;
      	int count =	this.getDbo().update(sql, new Object[]{tagname,tagnameng,ordernum,tcmstr,othernamestr,id});
      	
		return count + "";
	}
	/**
	 * 查询同义词
	 * @param tagname
	 * @param pid
	 * @param userid
	 * @param tagtype
	 * @return
	 */
	public String querySynnames(String itemid){
		//String seqid = this.getSeqValue("SEQ_SCHD_TAGS_ID");
		StringBuffer buffertcm = new StringBuffer();
		StringBuffer bufferxy = new StringBuffer();
		String sql = "select tagname,tagcode from SCHD_TAGS where pid=?" ;
      	List datalist =	this.getDbo().queryList(sql, new Object[]{itemid});
      	for(int i=0;i<datalist.size();i++){
      		Map data = (Map)datalist.get(i);
      		String tagname = (String)data.get("tagname");
      		String tagcode = (String)data.get("tagcode");
      		if(null == tagcode){
      			bufferxy.append(tagname).append(",\n");
      		}else{
      			buffertcm.append(tagname).append(",\n");
      		}
      	}
		return "<font size=3><strong>"+bufferxy.append(buffertcm).toString()+"</strong></font>";
	}
}
